package com.muse.sentinel.demo2.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.muse.sentinel.demo2.service.SentinelWithAnnotationService;

@RestController
public class SentinelSimpleDemoController {
    private static final int MAX_NUM = 50;

    @Resource
    private SentinelWithAnnotationService sentinelWithAnnotationService;

    /**
     * http://localhost:8000/process
     */
    @GetMapping("/process")
    public void process() {
        sentinelWithAnnotationService.initFlowRules(SentinelWithAnnotationService.FLOW_RULES_RESOURCES_PROCESS);
        int i = 0;
        while (i < MAX_NUM) {
            sentinelWithAnnotationService.process();
            i++;
        }
    }

    /**
     * http://localhost:8000/process1
     */
    @GetMapping("/process1")
    public void process1() {
        sentinelWithAnnotationService.initFlowRules(SentinelWithAnnotationService.FLOW_RULES_RESOURCES_PROCESS_1);
        int i = 0;
        while (i < MAX_NUM) {
            sentinelWithAnnotationService.process1();
            i++;
        }
    }

}
